package com.itheima.d8_interface2.Demo;

public class ClassDateInterImpl2 implements ClassDateInter{
    //把Students的数组传过来
    private Student[] students;

    public ClassDateInterImpl2(Student[] students) {
        this.students = students;
    }

    @Override
    public void printStudentInfo() {
        int maleCount = 0;
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            System.out.println("姓名：" + s.getName() + " 性别：" + s.getSex() + " 成绩：" + s.getScore());
            //打印男女人数
            if (s.getSex() == '男'){
                maleCount++;
            }

        }
        System.out.println("男生人数:"+maleCount);
        System.out.println("女生人数:"+(students.length-maleCount));
    }

    @Override
    public void printStudentAvgScore() {
        System.out.println("所有学生的平均分为：");
        Student s = students[0];
        double max = s.getScore();
        double min = s.getScore();
        double sum = s.getScore();
        for (int i = 1; i < students.length; i++) {
            //获取所有学生的信息
            s = students[i];
            sum += s.getScore();
            if(max < s.getScore()){
                max = s.getScore();
            }
            if (min > s.getScore()){
                min = s.getScore();
            }
        }
        System.out.println("最高分是：" +  max);
        System.out.println("最低分是：" +  min);
        System.out.println("平均分是：" +  (sum - max - min) / (students.length - 2));

    }
}
